import {
  methods,
  request,
} from '@/utils/request';//设置自己的request路径

const actions = {
  checkInStatus: {
    name: 'checkInStatus',
    url: '/api/activity/check-in/existence?',//打卡信息
  },
  getRegister: {
    name: 'getRegister',
    url: '/api/activity/getregister/',//获取自己报名情况
  },
  getStudentsCheck: {
    name: 'getStudentsCheck',
    url: '/api/activity/getstudentsinfo/',//根据活动id获取活动成员打卡情况
  },
  getSubActivityList: {
    name: 'getSubActivityList',
    url: '/api/activity/getsonactivityinfo/',//根据父活动id查找所有子活动
  },
  addfeedBackData: {
    name: 'addfeedBackData',
    url: '/api/activity/addfeedBackData', //插入/更新学生活动反馈信息stuCode、activityId、activityImpression、studentRating
  },
  createParentActivity: {
    name: 'createParentActivity',
    url: '/api/activity/createparent', //教师创建活动
  },
  getdetail: {
    name: 'getdetail',
    url: '/api/activity/getdetail/', //获取活动详情
  },
  getStuJoinList: {
    name: 'getStuJoinList',
    url: '/api/activity/getstudentsinfo/', //根据活动id获取打卡列表
  },
  getStuFeedBackInfo: {
    name: 'getStuFeedBackInfo',
    url: '/api/activity/feedbackall/', //根据活动id获取反馈列表
  },
  getAllRegister: {
    name: 'getAllRegister',
    url: '/api/activity/getAllRegister?activityId=', //根据活动id获取报名列表
  },
  getActivityByTeacher: {
    name: 'getActivityByTeacher',
    url: '/api/activity/teaall', //获取自己创建的活动列表
  },
  getActivityStatus: {
    name: 'getActivityStatus',
    url: '/api/activity/registerstatus/', //获取活动自己是否报名
  },
  setActivityPass:{
    name: 'setActivityPass',
    url: '/api/activity/passAudit'//设置学生活动报名通过
  },
  setActivityPulished: {
    name: 'setActivityPulished',
    url: '/api/activity/publishing/'
  },
};
const customRequest = (
  action: any,
  formdata: any = null,
) => {
  const options: any = {
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: localStorage.getItem("token")
    }
  };
  let url = action.url;
  switch (action.name) {
    case actions.checkInStatus.name:
      options['method'] = methods.get;
      url += "stuCode=" + formdata.stuCode + "&activityId=" + formdata.activityId
      break;
    case actions.getRegister.name:
      options['method'] = methods.get;
      url += formdata.stuCode + "/" + formdata.activityId
      break;
    case actions.getStudentsCheck.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getSubActivityList.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.createParentActivity.name:
      options['method'] = methods.post;
      options['body'] = formdata;
      break;
    case actions.getdetail.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getStuFeedBackInfo.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getStuJoinList.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getAllRegister.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getActivityByTeacher.name:
      options['method'] = methods.get;
      break;
    case actions.getActivityStatus.name:
      options['method'] = methods.get;
      url += formdata.activityId + "/" + formdata.stuNumber
      break;
    case actions.setActivityPass.name:
      options['method'] = methods.post;
      options['body'] =JSON.stringify(formdata) ;
      break;
    case actions.setActivityPulished.name:
      options['method'] = methods.put;
      url += formdata;
      break;

    default:
  }
  return request(url, options);
};

export function checkInStatus(formdata: any) {
  return customRequest(actions.checkInStatus, formdata);
}

export function getRegister(formdata: any) {
  return customRequest(actions.getRegister, formdata);
}

export function getSubActivityList(formdata: any) {
  return customRequest(actions.getSubActivityList, formdata);
}

export function createParentActivity(formdata: any) {
  return customRequest(actions.createParentActivity, formdata);
}

export function getdetail(formdata: any) {
  return customRequest(actions.getdetail, formdata);
}

export function getStuFeedBackInfo(formdata: any) {
  return customRequest(actions.getStuFeedBackInfo, formdata);
}

export function getStuJoinList(formdata: any) {
  return customRequest(actions.getStuJoinList, formdata);
}

export function getAllRegister(formdata: any) {
  return customRequest(actions.getAllRegister, formdata);
}
export function getActivityStatus(formdata: any) {
  return customRequest(actions.getActivityStatus, formdata);
}

export function getActivityByTeacher() {
  return customRequest(actions.getActivityByTeacher);
}
export function setActivityPass(formdata: any) {
  return customRequest(actions.setActivityPass, formdata);
}
export function setActivityPulished(formdata: any) {
  return customRequest(actions.setActivityPulished, formdata);
}

